<?php
class RaidKillRow extends Zend_Db_Table_Row_Abstract
{
	
	/*
	 * This function is called when delete() is called on a rowset
	 */
	protected function _delete()
	{
		//Iterates through all RaidDrops associated with this RaidKill
		$raidDrops = $this->findDependentRowset('RaidDrops','RaidKills');
		foreach($raidDrops as $drop){
			
			//deletes RaidDrop $drop
			$drop->delete();
		}
		//Deletes a possible DkpAdjustment associated with this RaidKill
		if($this->dkp_adjustment_id != null) $this->findParentRow('DkpAdjustments','DkpAdjustments')->delete();
	}
	
	/*
	 * Creates a new RaidDrop and its DkpAdjustment if dkp was spent on the drop
	 */
	public function addDrop($characterId,$itemId,$dkpSpent = null,$note = null)
	{
		$dkpAdjustmentId = null;
		if ($dkpSpent != null && $dkpSpent != 0){
			
			$dkpPoolId;
			$raid = $this->findParentRow('Raids','Raids');
			$currentDungeon = $raid->getDungeonToTime($this->time);
			if ($currentDungeon)$dkpPoolId = $currentDungeon->getDkpPoolId();
			else return false;			
			
			$dkpAdjustmentTable = new DkpAdjustments();
			$dkpAdjustment = $dkpAdjustmentTable->createAdjustment(DkpEvents::$LOOT, $raid->start_time, $characterId, $dkpPoolId, null, $dkpSpent, $note);
			$dkpAdjustmentId = $dkpAdjustment->id;
		}
		
		$raidDropsTable = new RaidDrops();
		$data = array(	'item_id'			=> $itemId,
						'raid_kills_id'		=> $this->id,
						'character_id'		=> $characterId,
						'dkp_adjustment_id'	=> $dkpAdjustmentId,
						'note'				=> $note
				);
		$raidDropsTable->insert($data);
		return true;
	}
	
	
	
	
}
?>

